package com.icss.ah.orderReview.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.icss.ah.base.bean.EasyuiDataGridJson;

@Service
@Transactional
public class OrderReviewService {
	
	private final Logger errlog = Logger.getLogger("E");
	private final Logger infolog = Logger.getLogger("I");
	
	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;
	private EasyuiDataGridJson dataGridJson = new EasyuiDataGridJson();
	
	/** 
	 * 列表查询
	 */
	public EasyuiDataGridJson queryOrderReviewList(Map<String, String> map){
		try {
			Long count = sqlSessionTemplate.selectOne("OrderReviewBean.queryOrderReviewExists",map);
			if(count>0)
				sqlSessionTemplate.insert("OrderReviewBean.insertOrderReview",map);
			List<Map<String, Object>> rows = sqlSessionTemplate.selectList("OrderReviewBean.queryOrderReviewList",map);
			Long total = sqlSessionTemplate.selectOne("OrderReviewBean.queryOrderReviewListCount",map);
			dataGridJson.setRows(rows);
			dataGridJson.setTotal(total);
			infolog.info("OrderReviewService|queryOrderReviewList|count:"+count+"|para:"+map+"|total:"+total);
		} catch (Exception e) {
			e.printStackTrace();
			errlog.error("OrderReviewService|queryOrderReviewList", e);
		}
		return dataGridJson;
	}
	
	public String reviewBatch(Map<String, String> map){
		String result = "f";
		try {
			sqlSessionTemplate.update("OrderReviewBean.reviewBatch",map);
			infolog.info("OrderReviewService|reviewBatch|para:"+map);
			result = "t";
		} catch (Exception e) {
			e.printStackTrace();
			errlog.error("OrderReviewService|reviewBatch", e);
		}
		return result;
	}
	
	public List<Map<String, Object>> exportOrderReviewList(Map<String, String> map){
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		try {
			list = sqlSessionTemplate.selectList("OrderReviewBean.exportOrderReviewList",map);
			infolog.info("OrderReviewService|exportOrderReviewList|para:"+map);
		} catch (Exception e) {
			e.printStackTrace();
			errlog.error("OrderReviewService|exportOrderReviewList", e);
		}
		return list;
	}

}
